﻿namespace AnyOffice.WorkFlowRegex
{
    using AnyOffice.Components;
    using log4net;
    using Microsoft.ApplicationBlocks.Data;
    using Microsoft.VisualBasic;
    using System;
    using System.Collections;
    using System.Data;
    using System.Data.SqlClient;
    using System.Text;
    using System.Text.RegularExpressions;
    using System.Web;
    using System.Configuration;
    using System.Reflection;

    public class FormControl
    {
        private bool _autoMacro = false;
        private string _class = "";
        private AnyOffice.WorkFlowRegex.ControlType _controlType = AnyOffice.WorkFlowRegex.ControlType.Default;
        private string _dataFld = "";
        private string _dataSrc = "";
        private string _formName = "";
        private bool _hidden = false;
        private string _lvSize = "";
        private string _lvTitle = "";
        private string _name;
        private Hashtable _prcsUser1 = new Hashtable();
        private Hashtable _prcsUser2 = new Hashtable();
        private bool _readOnly = false;
        private string _result = "";
        private DateTime _runDateTime = DateTime.Now;
        private int _runId = 0;
        private string _runName = "";
        private int _sequence = 0;
        private string _setValue = "";
        private string _source = "";
        private string _tag = "";
        private string _title = "";
        private string _type = "";
        private string _value = "";
        private string conn = ConfigurationManager.AppSettings["ConnectionString"];
        private static ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
        private HttpResponse reponse = HttpContext.Current.Response;

        private void AnalyzeControlType()
        {
            switch (this._controlType)
            {
                case AnyOffice.WorkFlowRegex.ControlType.Input:
                case AnyOffice.WorkFlowRegex.ControlType.TextArea:
                case AnyOffice.WorkFlowRegex.ControlType.ListView:
                case AnyOffice.WorkFlowRegex.ControlType.MacroInput:
                case AnyOffice.WorkFlowRegex.ControlType.Calculate:
                    this._source = "<INPUT name='DATA_" + this._sequence.ToString() + "' type=text size=30 class=SmallInput>";
                    break;

                case AnyOffice.WorkFlowRegex.ControlType.Select:
                {
                    this._source = VBString.Replace(this._source, "<SELECT", "<SELECT name='DATA_" + this._sequence + "' ");
                    this._source = VBString.Replace(this._source, "selected", "");
                    string pattern = @"<SELECT[^>]*?>(?<Option>(?:.|\n)*?)</SELECT>";
                    Regex regex = new Regex(pattern, RegexOptions.Compiled | RegexOptions.IgnoreCase);
                    if (regex.IsMatch(this._source))
                    {
                        Match match = regex.Match(this._source);
                        if (match.Success && match.Groups["Option"].Success) this._source = this._source.Substring(0, match.Groups["Option"].Index) + "<option value=''>所有</option>\n" + this._source.Substring(match.Groups["Option"].Index);
                        break;
                    }
                    break;
                }
                case AnyOffice.WorkFlowRegex.ControlType.Checkbox:
                    this._source = "<SELECT name=\"DATA_" + this._sequence.ToString() + "\" class=SmallSelect>\n";
                    this._source = this._source + "\t<option value=''>所有</option>\n";
                    this._source = this._source + "\t<option value='CHECKBOX_ON'>是</option>\n";
                    this._source = this._source + "\t<option value='CHECKBOX_OFF'>否</option>\n";
                    this._source = this._source + "</SELECT>\n";
                    break;

                case AnyOffice.WorkFlowRegex.ControlType.MacroSelect:
                    switch (this._dataFld.ToUpper())
                    {
                        case "SYS_LIST_DEPT":
                            this._source = "<SELECT name=\"DATA_" + this._sequence.ToString() + "\" class=SmallSelect>\n";
                            this._source = this._source + this.GetDepts();
                            this._source = this._source + "</SELECT>\n";
                            break;

                        case "SYS_LIST_PRIV":
                            this._source = "<SELECT name=\"DATA_" + this._sequence.ToString() + "\" class=SmallSelect>\n";
                            this._source = this._source + this.GetPrivs();
                            this._source = this._source + "</SELECT>\n";
                            break;

                        case "SYS_LIST_USER":
                        case "SYS_LIST_PRCSUSER1":
                        case "SYS_LIST_PRCSUSER2":
                            this._source = "<SELECT name=\"DATA_" + this._sequence.ToString() + "\" class=SmallSelect>\n";
                            this._source = this._source + this.GetUsers();
                            this._source = this._source + "</SELECT>\n";
                            break;

                        case "SYS_LIST_MANAGER1":
                            this._source = "<SELECT name=\"DATA_" + this._sequence.ToString() + "\" class=SmallSelect>\n";
                            this._source = this._source + this.GetUserName();
                            this._source = this._source + "</SELECT>\n";
                            break;

                        case "SYS_LIST_MANAGER2":
                            this._source = "<SELECT name=\"DATA_" + this._sequence.ToString() + "\" class=SmallSelect>\n";
                            this._source = this._source + this.GetUserNameInDept1();
                            this._source = this._source + "</SELECT>\n";
                            break;

                        case "SYS_LIST_MANAGER3":
                            this._source = "<SELECT name=\"DATA_" + this._sequence.ToString() + "\" class=SmallSelect>\n";
                            this._source = this._source + this.GetUserNameInDept2();
                            this._source = this._source + "</SELECT>\n";
                            break;

                        case "SYS_LIST_SQL":
                            this._source = "<INPUT name='DATA_" + this._sequence.ToString() + "' type=text size=30 class=SmallInput>";
                            break;
                    }
                    break;
            }
        }

        private void AnalyzeControlValue()
        {
            string str;
            Regex regex;
            string listSql;
            if (this._hidden)
                this._source = string.Empty;
            else
            {
                string str4;
                string s = "";
                listSql = "";
                string str7 = "";
                switch (this._controlType)
                {
                    case AnyOffice.WorkFlowRegex.ControlType.Input:
                        if (this._readOnly) this._source = VBString.Replace(this._source, "<INPUT", "<INPUT readonly class=BigStatic1 ");
                        if (this._value != this._setValue)
                        {
                            str = "\\svalue=(?:(?<value>[^\\s\"'>]+)|(?<value>\\w+)|\"(?<value>.*?)\"|\\'(?<value>.*?)\\')";
                            regex = new Regex(str, RegexOptions.Compiled | RegexOptions.IgnoreCase);
                            this._setValue = HttpContext.Current.Server.HtmlEncode(this._setValue);
                            if (regex.IsMatch(this._source))
                            {
                                Match match2 = regex.Match(this._source);
                                if (match2.Success) this._source = VBString.Replace(this._source, match2.Value, " value='" + this._setValue + "'");
                            }
                            else
                                this._source = VBString.Replace(this._source, "<INPUT", "<INPUT value='" + this._setValue + "' ");
                        }
                        return;

                    case AnyOffice.WorkFlowRegex.ControlType.TextArea:
                        if (this._readOnly) this._source = VBString.Replace(this._source, "<TEXTAREA", "<TEXTAREA readonly class=BigStatic1 ");
                        if (this._value != this._setValue)
                        {
                            str = @"<TEXTAREA[^>]*?>(?<Value>(?:.|\n)*?)</TEXTAREA>";
                            regex = new Regex(str, RegexOptions.Compiled | RegexOptions.IgnoreCase);
                            this._setValue = HttpContext.Current.Server.HtmlEncode(this._setValue);
                            if (regex.IsMatch(this._source))
                            {
                                Match match3 = regex.Match(this._source);
                                if (match3.Success && match3.Groups["Value"].Success)
                                {
                                    this.reponse.Write(match3.Groups["Value"].Value);
                                    this._source = this._source.Substring(0, match3.Groups["Value"].Index) + this._setValue + this._source.Substring(match3.Groups["Value"].Index + match3.Groups["Value"].Length);
                                }
                            }
                        }
                        return;

                    case AnyOffice.WorkFlowRegex.ControlType.Select:
                        if (this._readOnly)
                        {
                            this._source = VBString.Replace(this._source, "<SELECT", "<SELECT readonly class=BigStatic1 ");
                            str = @"<SELECT[^>]*?>(?<Option>(?:.|\n)*?)</SELECT>";
                            regex = new Regex(str, RegexOptions.Compiled | RegexOptions.IgnoreCase);
                            if (regex.IsMatch(this._source))
                            {
                                Match match5 = regex.Match(this._source);
                                if (match5.Success && match5.Groups["Option"].Success) this._source = this._source.Substring(0, match5.Groups["Option"].Index) + "<OPTION value='" + this._setValue + "'>" + this._setValue + "</OPTION>" + this._source.Substring(match5.Groups["Option"].Index + match5.Groups["Option"].Length);
                            }
                            return;
                        }
                        this._source = VBString.Replace(this._source, "selected", "");
                        str = "<OPTION[^>]*?(?<Option>value=(?:(?<Value>[^\\s\"'>]+)|\"(?<Value>.*?)\"|\\'(?<Value>.*?)\\')[^>]*?)>(?:.|\\n)*?</OPTION>";
                        regex = new Regex(str, RegexOptions.Compiled | RegexOptions.IgnoreCase);
                        for (Match match4 = regex.Match(this._source); match4.Success; match4 = match4.NextMatch())
                        {
                            if (match4.Groups["Option"].Success && match4.Groups["Value"].Success && match4.Groups["Value"].Value == this._setValue)
                            {
                                this._source = this._source.Substring(0, match4.Groups["Option"].Index) + "value=\"" + this._setValue + "\" selected" + this._source.Substring(match4.Groups["Option"].Index + match4.Groups["Option"].Length);
                                return;
                            }
                        }
                        return;

                    case AnyOffice.WorkFlowRegex.ControlType.Checkbox:
                        this._source = VBString.Replace(this._source, "CHECKED", " ");
                        if (this._setValue != "")
                        {
                            this._source = VBString.Replace(this._source, "<INPUT", "<INPUT CHECKED ");
                            if (this._readOnly) this._source = VBString.Replace(this._source, "<INPUT", "<INPUT readonly onclick='this.checked=true;' class=BigStatic1 ");
                            return;
                        }
                        if (this._readOnly) this._source = VBString.Replace(this._source, "<INPUT", "<INPUT readonly onclick='this.checked=false;' class=BigStatic1 ");
                        return;

                    case AnyOffice.WorkFlowRegex.ControlType.ListView:
                    {
                        string str2 = string.Empty;
                        string str3 = string.Empty;
                        string pattern = "\\s(?<tag>LV_SUM|LV_CAL)=(?:(?<value>[^\\s\"'>]+)|(?<value>\\w+)|\"(?<value>.*?)\"|\\'(?<value>.*?)\\')";
                        for (Match match = new Regex(pattern, RegexOptions.Compiled | RegexOptions.IgnoreCase).Match(this._dataSrc); match.Success; match = match.NextMatch())
                        {
                            if (match.Groups["tag"].Success && match.Groups["value"].Success && (str4 = match.Groups["tag"].Value.ToUpper()) != null)
                            {
                                if (str4 == "LV_SUM")
                                    str2 = match.Groups["value"].Value;
                                else if (str4 == "LV_CAL") str3 = match.Groups["value"].Value;
                            }
                        }
                        object obj3 = this._source;
                        this._source = string.Concat(new object[] { obj3, "<TABLE id='LV_", this._sequence, "' class='LIST_VIEW' style='border-collapse:collapse' border=1 cellspacing=0 cellpadding=2 bordercolor='#000000' FormData='", this._lvSize, "'>" });
                        this._source = this._source + "<TR class=TableHeader>";
                        if (this._lvTitle != string.Empty)
                        {
                            string[] strArray2 = this._lvTitle.Split(new char[] { '`' });
                            if (strArray2.Length > 0)
                            {
                                for (int i = 0; i < strArray2.Length - 1; i++)
                                {
                                    this._source = this._source + "<TD nowrap>" + strArray2[i] + "</TD>";
                                }
                            }
                        }
                        this._source = this._source + "<TD>操作</TD>";
                        this._source = this._source + "</TR></TABLE>";
                        if (!this._readOnly)
                        {
                            object obj4 = this._source;
                            this._source = string.Concat(new object[] { obj4, "<input type=button value=新增 onclick=\"tb_addnew('LV_", this._sequence, "',0,'','", str2, "','", str3, "')\">" });
                            if (str3.Replace("`", "") != string.Empty)
                            {
                                object obj5 = this._source;
                                this._source = string.Concat(new object[] { obj5, "<input type=button value=计算 onclick=\"tb_cal('LV_", this._sequence, "','", str3, "')\">" });
                            }
                        }
                        if (this._setValue != string.Empty)
                        {
                            this._setValue = this._setValue.Replace("\r", "");
                            this._setValue = this._setValue.Replace(@"\", @"\\");
                            this._setValue = this._setValue.Replace("'", @"\'");
                            if (this._setValue.EndsWith("\n")) this._setValue = this._setValue.Substring(0, this._setValue.Length - 1);
                            string[] strArray3 = this._setValue.Split(new char[] { '\n' });
                            if (strArray3.Length > 0)
                            {
                                this._source = this._source + "<SCRIPT>\n";
                                for (int j = 0; j < strArray3.Length; j++)
                                {
                                    object obj6 = this._source;
                                    this._source = string.Concat(new object[] { obj6, "tb_addnew('LV_", this._sequence, "',", this._readOnly ? "1" : "0", ",'", strArray3[j], "','", str2, "','", str3, "');" });
                                }
                                this._source = this._source + "</SCRIPT>\n";
                            }
                        }
                        if (str3.Replace("`", "") != string.Empty)
                        {
                            object obj7 = this._source;
                            this._source = string.Concat(new object[] { obj7, "<SCRIPT>setInterval(\"tb_cal('LV_", this._sequence, "','", str3, "')\",1000);</SCRIPT>" });
                        }
                        return;
                    }
                    case AnyOffice.WorkFlowRegex.ControlType.MacroInput:
                        DataTable table;
                        string str9;
                        if (this._readOnly)
                            this._source = VBString.Replace(this._source, "<INPUT", "<INPUT readonly class=BigStatic1 ");
                        else
                            this._source = VBString.Replace(this._source, "<INPUT", "<INPUT Onclick=\"auto_btn(ref_" + this._sequence.ToString() + ")\" ");
                        switch (this._dataFld.ToUpper())
                        {
                            case "SYS_YEAR":
                                s = DateTime.Now.ToString("yyyy");
                                break;

                            case "SYS_MON":
                                s = DateTime.Now.ToString("MM");
                                break;

                            case "SYS_DAY":
                                s = DateTime.Now.ToString("dd");
                                break;

                            case "SYS_HOUR":
                                s = DateTime.Now.ToString("HH");
                                break;

                            case "SYS_MIN":
                                s = DateTime.Now.ToString("mm");
                                break;

                            case "SYS_SEC":
                                s = DateTime.Now.ToString("ss");
                                break;

                            case "SYS_WEEK":
                            {
                                string[] strArray = new string[] { "日", "一", "二", "三", "四", "五", "六" };
                                s = "星期" + strArray[(int) DateTime.Now.DayOfWeek];
                                break;
                            }
                            case "SYS_DATE":
                                s = DateTime.Now.ToString("d");
                                break;

                            case "SYS_DATE_CN":
                                s = DateTime.Now.ToString("D");
                                break;

                            case "SYS_DATE_CN_SHORT1":
                                s = DateTime.Now.ToString("yyyy年M月");
                                break;

                            case "SYS_DATE_CN_SHORT2":
                                s = DateTime.Now.ToString("M月d日");
                                break;

                            case "SYS_TIME":
                                s = DateTime.Now.ToString("t");
                                break;

                            case "SYS_DATETIME":
                                s = DateTime.Now.ToString("g");
                                break;

                            case "SYS_USERID":
                                s = HttpContext.Current.User.Identity.Name;
                                break;

                            case "SYS_USERNAME":
                                if (HttpContext.Current.User.Identity.IsAuthenticated)
                                {
                                    try
                                    {
                                        str9 = "SELECT [UserName] FROM [dbo].[Users] WHERE [UserId] = '" + HttpContext.Current.User.Identity.Name + "'";
                                        table = SqlHelper.ExecuteDataset(this.conn, CommandType.Text, str9).Tables[0];
                                        if (table.Rows.Count > 0) s = table.Rows[0]["UserName"].ToString();
                                    }
                                    catch (Exception exception)
                                    {
                                        if (log.IsErrorEnabled) { log.Error("", exception); }
                                    }
                                }
                                break;

                            case "SYS_DEPTNAME":
                                if (HttpContext.Current.User.Identity.IsAuthenticated)
                                {
                                    try
                                    {
                                        s = this.GetDeptByUserId();
                                    }
                                    catch (Exception exception2)
                                    {
                                        if (log.IsErrorEnabled) { log.Error("", exception2); }
                                    }
                                }
                                break;

                            case "SYS_DEPTNAME_SHORT":
                                if (HttpContext.Current.User.Identity.IsAuthenticated)
                                {
                                    try
                                    {
                                        str9 = "SELECT [Department].[DeptName] FROM [dbo].[Users],[dbo].[Department] WHERE [Users].[UserId] = '" + HttpContext.Current.User.Identity.Name + "' AND [Users].[DeptId] = [Department].[DeptId]";
                                        table = SqlHelper.ExecuteDataset(this.conn, CommandType.Text, str9).Tables[0];
                                        if (table.Rows.Count > 0) s = table.Rows[0]["DeptName"].ToString();
                                    }
                                    catch (Exception exception3)
                                    {
                                        if (log.IsErrorEnabled) { log.Error("", exception3); }
                                    }
                                }
                                break;

                            case "SYS_USERPRIV":
                                if (HttpContext.Current.User.Identity.IsAuthenticated)
                                {
                                    try
                                    {
                                        str9 = "SELECT [User_Priv].[PrivName] FROM [dbo].[Users],[dbo].[User_Priv] WHERE [Users].[UserId] = '" + HttpContext.Current.User.Identity.Name + "' AND [Users].[PrivId] = [User_Priv].[PrivId]";
                                        table = SqlHelper.ExecuteDataset(this.conn, CommandType.Text, str9).Tables[0];
                                        if (table.Rows.Count > 0) s = table.Rows[0]["PrivName"].ToString();
                                    }
                                    catch (Exception exception4)
                                    {
                                        if (log.IsErrorEnabled) { log.Error("", exception4); }
                                    }
                                }
                                break;

                            case "SYS_USERNAME_DATE":
                                if (HttpContext.Current.User.Identity.IsAuthenticated)
                                {
                                    try
                                    {
                                        str9 = "SELECT [UserName] FROM [dbo].[Users] WHERE [UserId] = '" + HttpContext.Current.User.Identity.Name + "'";
                                        table = SqlHelper.ExecuteDataset(this.conn, CommandType.Text, str9).Tables[0];
                                        if (table.Rows.Count > 0) s = table.Rows[0]["UserName"].ToString();
                                        s = s + " " + DateTime.Now.ToString("yyyy-M-d");
                                    }
                                    catch (Exception exception5)
                                    {
                                        if (log.IsErrorEnabled) { log.Error("", exception5); }
                                    }
                                }
                                break;

                            case "SYS_USERNAME_DATETIME":
                                if (HttpContext.Current.User.Identity.IsAuthenticated)
                                {
                                    try
                                    {
                                        str9 = "SELECT [UserName] FROM [dbo].[Users] WHERE [UserId] = '" + HttpContext.Current.User.Identity.Name + "'";
                                        table = SqlHelper.ExecuteDataset(this.conn, CommandType.Text, str9).Tables[0];
                                        if (table.Rows.Count > 0) s = table.Rows[0]["UserName"].ToString();
                                        s = s + " " + DateTime.Now.ToString();
                                    }
                                    catch (Exception exception6)
                                    {
                                        if (log.IsErrorEnabled) log.Error("", exception6);
                                    }
                                }
                                break;

                            case "SYS_FORMNAME":
                                s = this._formName;
                                break;

                            case "SYS_RUNNAME":
                                s = this._runName;
                                break;

                            case "SYS_RUNDATE":
                                s = this._runDateTime.ToString("d");
                                break;

                            case "SYS_RUNDATETIME":
                                s = this._runDateTime.ToString("g");
                                break;

                            case "SYS_RUNID":
                                s = this._runId.ToString();
                                break;

                            case "SYS_AUTONUM":
                                try
                                {
                                    str9 = "SELECT [AutoNum] FROM [dbo].[Flow_Run],[dbo].[Flow_Type] WHERE [Flow_Run].[RunId] = " + this._runId.ToString() + " AND [Flow_Run].[FlowId] = [Flow_Type].[FlowId]";
                                    DataTable table2 = SqlHelper.ExecuteDataset(this.conn, CommandType.Text, str9).Tables[0];
                                    if (table2.Rows.Count > 0) s = table2.Rows[0]["AutoNum"].ToString();
                                }
                                catch (Exception exception7)
                                {
                                    if (log.IsErrorEnabled) log.Error("", exception7);
                                }
                                break;

                            case "SYS_IP":
                                s = HttpContext.Current.Request.UserHostAddress;
                                break;

                            case "SYS_SQL":
                                if (this._dataSrc != "")
                                {
                                    try
                                    {
                                        this._dataSrc = this._dataSrc.Replace("`", "'");
                                        if (this._dataSrc.ToUpper().IndexOf("[SYS_USER_ID]") >= 0) this._dataSrc = VBString.Replace(this._dataSrc, "[SYS_USER_ID]", HttpContext.Current.User.Identity.Name);
                                        if (this._dataSrc.ToUpper().IndexOf("[SYS_DEPT_ID]") > -1 || this._dataSrc.ToUpper().IndexOf("[SYS_PRIV_ID]") > -1)
                                        {
                                            UserCache cache = new UserCache();
                                            this._dataSrc = VBString.Replace(this._dataSrc, "[SYS_DEPT_ID]", cache.DeptId.ToString());
                                            this._dataSrc = VBString.Replace(this._dataSrc, "[SYS_PRIV_ID]", cache.PrivId.ToString());
                                        }
                                        if (this._dataSrc.ToUpper().IndexOf("[SYS_RUN_ID]") >= 0) this._dataSrc = VBString.Replace(this._dataSrc, "[SYS_RUN_ID]", this._runId.ToString());
                                        object obj2 = SqlHelper.ExecuteScalar(this.conn, CommandType.Text, this._dataSrc);
                                        if (obj2 != null && obj2 != DBNull.Value) s = HttpContext.Current.Server.HtmlEncode(obj2.ToString());
                                    }
                                    catch (Exception exception8)
                                    {
                                        s = "SQL错误";
                                        if (log.IsErrorEnabled) log.Error("", exception8);
                                    }
                                }
                                break;
                        }
                        str7 = s;
                        if (!(!(this._setValue != "{宏控件}") || !(this._setValue != "") || this._readOnly)) s = this._setValue;
                        if (this._readOnly && !this._autoMacro)
                        {
                            if (this._setValue != "{宏控件}")
                                s = this._setValue;
                            else
                                s = "";
                        }
                        else if (this._setValue != "{宏控件}" && this._setValue != "") s = this._setValue;
                        str = "\\svalue=(?:(?<value>[^\\s\"'>]+)|(?<value>\\w+)|\"(?<value>.*?)\"|\\'(?<value>.*?)\\')";
                        regex = new Regex(str, RegexOptions.Compiled | RegexOptions.IgnoreCase);
                        s = HttpContext.Current.Server.HtmlEncode(s);
                        if (regex.IsMatch(this._source))
                        {
                            Match match6 = regex.Match(this._source);
                            if (match6.Success) this._source = VBString.Replace(this._source, match6.Value, " value='" + s + "'");
                        }
                        else
                            this._source = VBString.Replace(this._source, "<INPUT", "<INPUT value='" + s + "' ");
                        if (!this._readOnly)
                        {
                            str4 = this._source;
                            this._source = str4 + "<INPUT type=\"button\" id=\"ref_" + this._sequence.ToString() + "\" style=\"display:none\" title=\"重新获取系统当前值\" value=\"刷新\" border=0 onclick=\"document.Form1.DATA_" + this._sequence.ToString() + ".value='" + str7 + "'\">";
                        }
                        return;

                    case AnyOffice.WorkFlowRegex.ControlType.MacroSelect:
                        if (this._readOnly) this._source = VBString.Replace(this._source, "<SELECT", "<SELECT readonly class=BigStatic1 ");
                        switch (this._dataFld.ToUpper())
                        {
                            case "SYS_LIST_DEPT":
                                listSql = this.GetList_Dept();
                                goto Label_1571;

                            case "SYS_LIST_USER":
                                listSql = this.GetList_User();
                                goto Label_1571;

                            case "SYS_LIST_PRIV":
                                listSql = this.GetList_Priv();
                                goto Label_1571;

                            case "SYS_LIST_PRCSUSER1":
                                listSql = this.GetLIST_PRCSUSER1();
                                goto Label_1571;

                            case "SYS_LIST_PRCSUSER2":
                                listSql = this.GetLIST_PRCSUSER2();
                                goto Label_1571;

                            case "SYS_LIST_MANAGER1":
                                listSql = this.GetLIST_MANAGER1();
                                goto Label_1571;

                            case "SYS_LIST_MANAGER2":
                                listSql = this.GetLIST_MANAGER2();
                                goto Label_1571;

                            case "SYS_LIST_MANAGER3":
                                listSql = this.GetLIST_MANAGER3();
                                goto Label_1571;

                            case "SYS_LIST_SQL":
                                listSql = this.GetListSql();
                                goto Label_1571;
                        }
                        goto Label_1571;

                    case AnyOffice.WorkFlowRegex.ControlType.Calculate:
                        if (this._readOnly) this._source = VBString.Replace(this._source, "<INPUT", "<INPUT readonly class=BigStatic1 ");
                        return;
                }
            }
            return;
        Label_1571:
            str = @"<SELECT[^>]*?>(?<Option>(?:.|\n)*?)</SELECT>";
            regex = new Regex(str, RegexOptions.Compiled | RegexOptions.IgnoreCase);
            if (regex.IsMatch(this._source))
            {
                Match match7 = regex.Match(this._source);
                if (match7.Success && match7.Groups["Option"].Success) this._source = this._source.Substring(0, match7.Groups["Option"].Index) + listSql + this._source.Substring(match7.Groups["Option"].Index + match7.Groups["Option"].Length);
            }
        }

        private void AnalyzeTagName()
        {
            string str = this._tag;
            switch (str)
            {
                case null:
                    break;

                case "INPUT":
                    this._source = VBString.Replace(this._source, "<INPUT", string.Concat(new object[] { "<INPUT id='DATA_", this._sequence, "' name='DATA_", this._sequence, "' " }));
                    break;

                case "TEXTAREA":
                    this._source = VBString.Replace(this._source, "<TEXTAREA", string.Concat(new object[] { "<TEXTAREA id='DATA_", this._sequence, "' name='DATA_", this._sequence, "' " }));
                    break;

                default:
                    if (!(str == "SELECT"))
                    {
                        if (str == "IMG" && this._class.ToUpper() == "LIST_VIEW")
                        {
                            this._dataSrc = this._source;
                            this._source = string.Concat(new object[] { "<input type=hidden id='DATA_", this._sequence, "' name='DATA_", this._sequence, "' value=\"", HttpContext.Current.Server.HtmlEncode(this._setValue), "\">" });
                        }
                    }
                    else
                        this._source = VBString.Replace(this._source, "<SELECT", string.Concat(new object[] { "<SELECT id='DATA_", this._sequence, "' name='DATA_", this._sequence, "' " }));
                    break;
            }
        }

        private void AnalyzeTagType()
        {
            string str = this._tag.ToUpper();
            switch (str)
            {
                case null:
                    break;

                case "INPUT":
                    if (this._type.ToUpper() == "CHECKBOX")
                        this._controlType = AnyOffice.WorkFlowRegex.ControlType.Checkbox;
                    else if (this._class.ToUpper() == "CALC")
                        this._controlType = AnyOffice.WorkFlowRegex.ControlType.Calculate;
                    else if (this._dataFld.ToUpper() != "")
                        this._controlType = AnyOffice.WorkFlowRegex.ControlType.MacroInput;
                    else
                        this._controlType = AnyOffice.WorkFlowRegex.ControlType.Input;
                    break;

                case "TEXTAREA":
                    this._controlType = AnyOffice.WorkFlowRegex.ControlType.TextArea;
                    break;

                default:
                    if (!(str == "SELECT"))
                    {
                        if (str == "IMG" && this._class.ToUpper() == "LIST_VIEW") this._controlType = AnyOffice.WorkFlowRegex.ControlType.ListView;
                    }
                    else if (this._dataFld != "")
                        this._controlType = AnyOffice.WorkFlowRegex.ControlType.MacroSelect;
                    else
                        this._controlType = AnyOffice.WorkFlowRegex.ControlType.Select;
                    break;
            }
        }

        private void AnalyzeType()
        {
            string pattern = "\\s(?<tag>\\w+)=(?:(?<value>[^\\s\"'>]+)|(?<value>\\w+)|\"(?<value>.*?)\"|\\'(?<value>.*?)\\')";
            Regex regex = new Regex(pattern, RegexOptions.Compiled | RegexOptions.IgnoreCase);
            for (Match match = regex.Match(this._source); match.Success; match = match.NextMatch())
            {
                if (match.Groups["tag"].Success && match.Groups["value"].Success)
                {
                    switch (match.Groups["tag"].Value.ToUpper())
                    {
                        case "NAME":
                            this._name = match.Groups["value"].Value;
                            break;

                        case "TYPE":
                            this._type = match.Groups["value"].Value;
                            break;

                        case "CLASS":
                            this._class = match.Groups["value"].Value;
                            break;

                        case "DATAFLD":
                            this._dataFld = match.Groups["value"].Value;
                            break;

                        case "DATASRC":
                            this._dataSrc = match.Groups["value"].Value;
                            break;

                        case "LV_TITLE":
                            this._lvTitle = match.Groups["value"].Value;
                            break;

                        case "LV_SIZE":
                            this._lvSize = match.Groups["value"].Value;
                            break;

                        case "VALUE":
                            if (!(this._tag == "SELECT")) this._value = match.Groups["value"].Value;
                            break;
                    }
                }
            }
        }

        public void BaseAttributeAnalyze()
        {
            this.AnalyzeType();
            this.AnalyzeTagType();
        }

        protected void ChildDepartment(SqlConnection conn, ref string MacroOptionSelect, int DeptId, string strTemp)
        {
            string str = "";
            string str2 = "SELECT [DeptId],[DeptName] FROM [dbo].[Department] WHERE [ParentDept]=" + DeptId.ToString() + " ORDER BY [DeptNo] ASC";
            DataTable table = SqlHelper.ExecuteDataset(conn, CommandType.Text, str2).Tables[0];
            if (table.Rows.Count > 0)
            {
                strTemp = strTemp + "|　";
                for (int i = 0; i < table.Rows.Count; i++)
                {
                    if (this._setValue == table.Rows[i]["DeptId"].ToString()) str = " selected";
                    if (!((!this._readOnly || this._setValue != table.Rows[i]["DeptId"].ToString()) && this._readOnly))
                    {
                        string str3 = MacroOptionSelect;
                        MacroOptionSelect = str3 + "<OPTION " + str + " value='" + table.Rows[i]["DeptId"].ToString() + "'>" + strTemp + "|─" + table.Rows[i]["DeptName"].ToString() + "</OPTION>\n";
                    }
                    str = "";
                    this.ChildDepartment(conn, ref MacroOptionSelect, int.Parse(table.Rows[i]["DeptId"].ToString()), strTemp);
                }
            }
        }

        public string DataOrCalculate(ArrayList Title, string ProcessItem, bool IsFixedFlow)
        {
            this.AnalyzeType();
            if (this._class.ToUpper() == "DATE")
            {
                if (!(IsFixedFlow && (!IsFixedFlow || ProcessItem.IndexOf(this._value) <= 0)))
                {
                    for (int i = 0; i < Title.Count; i++)
                    {
                        if (this._value == Title[i].ToString()) this._source = VBString.Replace(this._source, "<IMG", "<IMG onclick=\"popUpCalendar(this,DATA_" + Convert.ToString((int) (i + 1)) + ",'yyyy-mm-dd','');\" ");
                    }
                    string pattern = "\\ssrc=(?:(?<value>[^\\s\"'>]+)|(?<value>\\w+)|\"(?<value>.*?)\"|\\'(?<value>.*?)\\')";
                    Match match = new Regex(pattern, RegexOptions.Compiled | RegexOptions.IgnoreCase).Match(this._source);
                    if (match.Success) this._source = VBString.Replace(this._source, match.Value, " src=\"/images/calendar.gif\"");
                }
                else
                    this._source = "";
            }
            if (this._class.ToUpper() == "USER")
            {
                if (!(IsFixedFlow && (!IsFixedFlow || ProcessItem.IndexOf(this._value) <= 0)))
                {
                    for (int j = 0; j < Title.Count; j++)
                    {
                        if (this._value == Title[j].ToString()) this._source = VBString.Replace(this._source, "<IMG", "<IMG onclick=\"popDeptUser('DATA_" + Convert.ToString((int) (j + 1)) + "');\" ");
                    }
                    string str2 = "\\ssrc=(?:(?<value>[^\\s\"'>]+)|(?<value>\\w+)|\"(?<value>.*?)\"|\\'(?<value>.*?)\\')";
                    Match match2 = new Regex(str2, RegexOptions.Compiled | RegexOptions.IgnoreCase).Match(this._source);
                    if (match2.Success) this._source = VBString.Replace(this._source, match2.Value, " src=\"/images/form/user.gif\"");
                }
                else
                    this._source = "";
            }
            else if (this._class.ToUpper() == "CALC")
            {
                string expression = this._value;
                this._sequence = Convert.ToInt32(this._name.Substring(5));
                for (int k = 0; k < Title.Count; k++)
                {
                    expression = VBString.Replace(expression, Title[k].ToString(), "parseFloat(document.Form1.DATA_" + Convert.ToString((int) (k + 1)) + ".value)");
                }
                StringBuilder builder = new StringBuilder();
                builder.Append("\n<script>\n");
                builder.Append("function calc_" + this._sequence.ToString() + "()\n");
                builder.Append("{\n");
                builder.Append("myvalue=" + expression + ";\n");
                builder.Append("if(!isNaN(myvalue))\n");
                builder.Append("    document.Form1." + this._name + ".value=Math.round(myvalue * 100)/100;\n");
                builder.Append("else\n");
                builder.Append("    document.Form1." + this._name + ".value=\"\";");
                builder.Append("setTimeout(\"calc_" + this._sequence.ToString() + "()\",1000);");
                builder.Append("\n}\n");
                builder.Append("calc_" + this._sequence.ToString() + "();");
                builder.Append("</script>\n");
                string str4 = "\\svalue=(?:(?<value>[^\\s\"'>]+)|(?<value>\\w+)|\"(?<value>.*?)\"|\\'(?<value>.*?)\\')";
                Match match3 = new Regex(str4, RegexOptions.Compiled | RegexOptions.IgnoreCase).Match(this._source);
                if (match3.Success) this._source = VBString.Replace(this._source, match3.Value, "");
                this._source = this._source + builder.ToString();
            }
            this._result = this._source;
            return this._result;
        }

        private string GetDeptByUserId()
        {
            string strTemp = string.Empty;
            SqlConnection conn = new SqlConnection(this.conn);
            conn.Open();
            string str2 = "SELECT [Department].[ParentDept],[Department].[DeptName] FROM [dbo].[Users],[dbo].[Department] WHERE [Users].[UserId] = '" + HttpContext.Current.User.Identity.Name + "' AND [Users].[DeptId] = [Department].[DeptId]";
            DataTable table = SqlHelper.ExecuteDataset(conn, CommandType.Text, str2).Tables[0];
            if (table.Rows.Count > 0)
            {
                strTemp = table.Rows[0]["DeptName"].ToString();
                if (Convert.ToInt32(table.Rows[0]["ParentDept"].ToString()) != 0) this.PrentDeptName(conn, Convert.ToInt32(table.Rows[0]["ParentDept"].ToString()), ref strTemp);
            }
            conn.Close();
            return strTemp;
        }

        private string GetDepts()
        {
            string macroOptionSelect = "";
            string strTemp = "";
            macroOptionSelect = "\n<OPTION value=''>所有</OPTION>\n";
            SqlConnection conn = new SqlConnection(this.conn);
            conn.Open();
            string str3 = "SELECT [DeptId],[DeptName] FROM [dbo].[Department] WHERE [ParentDept]=0 AND [DeptId] <> -1 ORDER BY [DeptNo] ASC";
            DataTable table = SqlHelper.ExecuteDataset(conn, CommandType.Text, str3).Tables[0];
            if (table.Rows.Count > 0)
            {
                for (int i = 0; i < table.Rows.Count; i++)
                {
                    string str4 = macroOptionSelect;
                    macroOptionSelect = str4 + "<OPTION value='" + table.Rows[i]["DeptId"].ToString() + "'>|─" + table.Rows[i]["DeptName"].ToString() + "</OPTION>\n";
                    strTemp = "";
                    this.QueryChildDepartment(conn, ref macroOptionSelect, int.Parse(table.Rows[i]["DeptId"].ToString()), strTemp);
                }
            }
            conn.Close();
            return macroOptionSelect;
        }

        private string GetList_Dept()
        {
            string macroOptionSelect = "";
            string strTemp = "";
            string str3 = "";
            if (!(this._readOnly && !(this._setValue == ""))) macroOptionSelect = "\n<OPTION value=''></OPTION>\n";
            SqlConnection conn = new SqlConnection(this.conn);
            conn.Open();
            string str4 = "SELECT [DeptId],[DeptName] FROM [dbo].[Department] WHERE [ParentDept]=0 AND [DeptId] <> -1 ORDER BY [DeptNo] ASC";
            DataTable table = SqlHelper.ExecuteDataset(conn, CommandType.Text, str4).Tables[0];
            if (table.Rows.Count > 0)
            {
                for (int i = 0; i < table.Rows.Count; i++)
                {
                    if (this._setValue == table.Rows[i]["DeptId"].ToString()) str3 = " selected";
                    if (!((!this._readOnly || this._setValue != table.Rows[i]["DeptId"].ToString()) && this._readOnly))
                    {
                        string str5 = macroOptionSelect;
                        macroOptionSelect = str5 + "<OPTION " + str3 + " value='" + table.Rows[i]["DeptId"].ToString() + "'>|─" + table.Rows[i]["DeptName"].ToString() + "</OPTION>\n";
                    }
                    str3 = "";
                    strTemp = "";
                    this.ChildDepartment(conn, ref macroOptionSelect, int.Parse(table.Rows[i]["DeptId"].ToString()), strTemp);
                }
            }
            conn.Close();
            return macroOptionSelect;
        }

        private string GetLIST_MANAGER1()
        {
            string str = "";
            string str2 = "";
            if (!(this._readOnly && !(this._setValue == ""))) str = "\n<OPTION value=''></OPTION>\n";
            string str3 = "SELECT A.[UserId], A.[UserName] FROM [dbo].[Department], [dbo].[Users] AS A, [dbo].[Users] AS B WHERE B.[UserId] = '" + HttpContext.Current.User.Identity.Name + "' AND [Department].[DeptId] = B.[DeptId] AND CHARINDEX(',' + A.[UserId] + ',',',' + ISNULL(CAST([Department].[Manager] AS nvarchar(2000)),'') + ',') > 0 ORDER BY A.[UserNo] ASC";
            DataTable table = SqlHelper.ExecuteDataset(this.conn, CommandType.Text, str3).Tables[0];
            if (table.Rows.Count > 0)
            {
                for (int i = 0; i < table.Rows.Count; i++)
                {
                    if (this._setValue == table.Rows[i]["UserId"].ToString()) str2 = " selected";
                    if (!((!this._readOnly || this._setValue != table.Rows[i]["UserId"].ToString()) && this._readOnly))
                    {
                        string str4 = str;
                        str = str4 + "<OPTION " + str2 + " value='" + table.Rows[i]["UserId"].ToString() + "'>" + table.Rows[i]["UserName"].ToString() + "</OPTION>\n";
                    }
                    str2 = "";
                }
            }
            return str;
        }

        private string GetLIST_MANAGER2()
        {
            string str = "";
            string str2 = "";
            if (!(this._readOnly && !(this._setValue == ""))) str = "\n<OPTION value=''></OPTION>\n";
            string str3 = "SELECT A.[UserId], A.[UserName] FROM [dbo].[Department], [dbo].[Users] AS A, [dbo].[Users] AS B WHERE B.[UserId] = '" + HttpContext.Current.User.Identity.Name + "' AND [Department].[DeptId] = B.[DeptId] AND CHARINDEX(',' + A.[UserId] + ',',',' + ISNULL(CAST([Department].[Leader1] AS nvarchar(2000)),'') + ',') > 0 ORDER BY A.[UserNo] ASC";
            DataTable table = SqlHelper.ExecuteDataset(this.conn, CommandType.Text, str3).Tables[0];
            if (table.Rows.Count > 0)
            {
                for (int i = 0; i < table.Rows.Count; i++)
                {
                    if (this._setValue == table.Rows[i]["UserId"].ToString()) str2 = " selected";
                    if (!((!this._readOnly || this._setValue != table.Rows[i]["UserId"].ToString()) && this._readOnly))
                    {
                        string str4 = str;
                        str = str4 + "<OPTION " + str2 + " value='" + table.Rows[i]["UserId"].ToString() + "'>" + table.Rows[i]["UserName"].ToString() + "</OPTION>\n";
                    }
                    str2 = "";
                }
            }
            return str;
        }

        private string GetLIST_MANAGER3()
        {
            string str = "";
            string str2 = "";
            if (!(this._readOnly && !(this._setValue == ""))) str = "\n<OPTION value=''></OPTION>\n";
            string str3 = "SELECT A.[UserId], A.[UserName] FROM [dbo].[Department], [dbo].[Users] AS A, [dbo].[Users] AS B WHERE B.[UserId] = '" + HttpContext.Current.User.Identity.Name + "' AND [Department].[DeptId] = B.[DeptId] AND CHARINDEX(',' + A.[UserId] + ',',',' + ISNULL(CAST([Department].[Leader2] AS nvarchar(2000)),'') + ',') > 0 ORDER BY A.[UserNo] ASC";
            DataTable table = SqlHelper.ExecuteDataset(this.conn, CommandType.Text, str3).Tables[0];
            if (table.Rows.Count > 0)
            {
                for (int i = 0; i < table.Rows.Count; i++)
                {
                    if (this._setValue == table.Rows[i]["UserId"].ToString()) str2 = " selected";
                    if (!((!this._readOnly || this._setValue != table.Rows[i]["UserId"].ToString()) && this._readOnly))
                    {
                        string str4 = str;
                        str = str4 + "<OPTION " + str2 + " value='" + table.Rows[i]["UserId"].ToString() + "'>" + table.Rows[i]["UserName"].ToString() + "</OPTION>\n";
                    }
                    str2 = "";
                }
            }
            return str;
        }

        private string GetLIST_PRCSUSER1()
        {
            string str = "";
            string str2 = "";
            if (!(this._readOnly && !(this._setValue == ""))) str = "\n<OPTION value=''></OPTION>\n";
            if (this._prcsUser1.Count > 0)
            {
                IDictionaryEnumerator enumerator = this._prcsUser1.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    if (this._setValue == enumerator.Key.ToString()) str2 = " selected";
                    if (!((!this._readOnly || this._setValue != enumerator.Key.ToString()) && this._readOnly))
                    {
                        string str3 = str;
                        str = str3 + "<OPTION " + str2 + " value='" + enumerator.Key.ToString() + "'>" + enumerator.Value.ToString() + "</OPTION>\n";
                    }
                    str2 = "";
                }
            }
            return str;
        }

        private string GetLIST_PRCSUSER2()
        {
            string str = "";
            string str2 = "";
            if (!(this._readOnly && !(this._setValue == ""))) str = "\n<OPTION value=''></OPTION>\n";
            if (this._prcsUser2.Count > 0)
            {
                IDictionaryEnumerator enumerator = this._prcsUser2.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    if (this._setValue == enumerator.Key.ToString()) str2 = " selected";
                    if (!((!this._readOnly || this._setValue != enumerator.Key.ToString()) && this._readOnly))
                    {
                        string str3 = str;
                        str = str3 + "<OPTION " + str2 + " value='" + enumerator.Key.ToString() + "'>" + enumerator.Value.ToString() + "</OPTION>\n";
                    }
                    str2 = "";
                }
            }
            return str;
        }

        private string GetList_Priv()
        {
            string str = "";
            string str2 = "";
            if (!(this._readOnly && !(this._setValue == ""))) str = "\n<OPTION value=''></OPTION>\n";
            string str3 = "SELECT [PrivId],[PrivName] FROM [dbo].[User_Priv] ORDER BY [PrivNo] ASC";
            DataTable table = SqlHelper.ExecuteDataset(this.conn, CommandType.Text, str3).Tables[0];
            if (table.Rows.Count > 0)
            {
                for (int i = 0; i < table.Rows.Count; i++)
                {
                    if (this._setValue == table.Rows[i]["PrivId"].ToString()) str2 = " selected";
                    if (!((!this._readOnly || this._setValue != table.Rows[i]["PrivId"].ToString()) && this._readOnly))
                    {
                        string str4 = str;
                        str = str4 + "<OPTION " + str2 + " value='" + table.Rows[i]["PrivId"].ToString() + "'>" + table.Rows[i]["PrivName"].ToString() + "</OPTION>\n";
                    }
                    str2 = "";
                }
            }
            return str;
        }

        private string GetList_User()
        {
            string str = "";
            string str2 = "";
            if (!(this._readOnly && !(this._setValue == ""))) str = "\n<OPTION value=''></OPTION>\n";
            string str3 = "SELECT [Users].[UserId],[Users].[UserName] FROM [dbo].[Department],[dbo].[Users] WHERE ([Department].[DeptId] = [Users].[DeptId]) AND ([Users].[DeptId] <> -1) ORDER BY [Department].[DeptId] ASC,[Users].[UserNo] ASC";
            DataTable table = SqlHelper.ExecuteDataset(this.conn, CommandType.Text, str3).Tables[0];
            if (table.Rows.Count > 0)
            {
                for (int i = 0; i < table.Rows.Count; i++)
                {
                    if (this._setValue == table.Rows[i]["UserId"].ToString()) str2 = " selected";
                    if (!((!this._readOnly || this._setValue != table.Rows[i]["UserId"].ToString()) && this._readOnly))
                    {
                        string str4 = str;
                        str = str4 + "<OPTION " + str2 + " value='" + table.Rows[i]["UserId"].ToString() + "'>" + table.Rows[i]["UserName"].ToString() + "</OPTION>\n";
                    }
                    str2 = "";
                }
            }
            return str;
        }

        private string GetListSql()
        {
            string str = "";
            string str2 = "";
            if (!(this._readOnly && !(this._setValue == ""))) str = "<OPTION value=''></OPTION>\n";
            if (this._dataSrc != "")
            {
                try
                {
                    this._dataSrc = this._dataSrc.Replace("`", "'");
                    if (this._dataSrc.ToUpper().IndexOf("[SYS_USER_ID]") >= 0) this._dataSrc = VBString.Replace(this._dataSrc, "[SYS_USER_ID]", HttpContext.Current.User.Identity.Name);
                    if (this._dataSrc.ToUpper().IndexOf("[SYS_DEPT_ID]") > -1 || this._dataSrc.ToUpper().IndexOf("[SYS_PRIV_ID]") > -1)
                    {
                        UserCache cache = new UserCache();
                        this._dataSrc = VBString.Replace(this._dataSrc, "[SYS_DEPT_ID]", cache.DeptId.ToString());
                        this._dataSrc = VBString.Replace(this._dataSrc, "[SYS_PRIV_ID]", cache.PrivId.ToString());
                    }
                    if (this._dataSrc.ToUpper().IndexOf("[SYS_RUN_ID]") >= 0) this._dataSrc = VBString.Replace(this._dataSrc, "[SYS_RUN_ID]", this._runId.ToString());
                    DataTable table = SqlHelper.ExecuteDataset(this.conn, CommandType.Text, this._dataSrc).Tables[0];
                    if (table.Rows.Count <= 0) return str;
                    for (int i = 0; i < table.Rows.Count; i++)
                    {
                        if (table.Rows[i][0] != DBNull.Value && this._setValue == table.Rows[i][0].ToString()) str2 = " selected";
                        if (this._readOnly && this._setValue == table.Rows[i][0].ToString() || !this._readOnly)
                        {
                            if (table.Rows[i][0] != DBNull.Value)
                            {
                                string str3 = str;
                                str = str3 + "<OPTION " + str2 + " value='" + HttpContext.Current.Server.HtmlEncode(table.Rows[i][0].ToString()) + "'>" + HttpContext.Current.Server.HtmlEncode(table.Rows[i][0].ToString()) + "</OPTION>\n";
                            }
                            else
                                str = str + "<OPTION></OPTION>\n";
                        }
                        str2 = "";
                    }
                }
                catch (Exception exception)
                {
                    str = str + "<OPTION value=''>SQL错误</OPTION>\n";
                    if (log.IsErrorEnabled) { log.Error("", exception); }
                }
            }
            return str;
        }

        private string GetPrivs()
        {
            string str = "";
            str = "\n<OPTION value=''>所有</OPTION>\n";
            string str2 = "SELECT [PrivId],[PrivName] FROM [dbo].[User_Priv] ORDER BY [PrivNo] ASC";
            DataTable table = SqlHelper.ExecuteDataset(this.conn, CommandType.Text, str2).Tables[0];
            if (table.Rows.Count > 0)
            {
                for (int i = 0; i < table.Rows.Count; i++)
                {
                    string str3 = str;
                    str = str3 + "<OPTION value='" + table.Rows[i]["PrivId"].ToString() + "'>" + table.Rows[i]["PrivName"].ToString() + "</OPTION>\n";
                }
            }
            return str;
        }

        private void getSourceName()
        {
            string str;
            if (this._hidden)
                this._source = string.Empty;
            else
            {
                switch (this._controlType)
                {
                    case AnyOffice.WorkFlowRegex.ControlType.Input:
                        this._source = HttpContext.Current.Server.HtmlEncode(this._setValue);
                        return;

                    case AnyOffice.WorkFlowRegex.ControlType.TextArea:
                        this._source = HttpContext.Current.Server.HtmlEncode(this._setValue);
                        this._source = this._source.Replace("\r\n", "<br>").Replace(" ", "&nbsp;");
                        return;

                    case AnyOffice.WorkFlowRegex.ControlType.Select:
                        this._source = this._setValue;
                        return;

                    case AnyOffice.WorkFlowRegex.ControlType.Checkbox:
                        if (this._setValue != string.Empty)
                        {
                            this._source = "<input type=checkbox onclick='this.checked=true;' checked>";
                            return;
                        }
                        this._source = "<input type=checkbox onclick='this.checked=false;'>";
                        return;

                    case AnyOffice.WorkFlowRegex.ControlType.ListView:
                    {
                        string str2 = string.Empty;
                        string pattern = "\\s(?<tag>LV_SUM|LV_CAL)=(?:(?<value>[^\\s\"'>]+)|(?<value>\\w+)|\"(?<value>.*?)\"|\\'(?<value>.*?)\\')";
                        Regex regex = new Regex(pattern, RegexOptions.Compiled | RegexOptions.IgnoreCase);
                        for (Match match = regex.Match(this._dataSrc); match.Success; match = match.NextMatch())
                        {
                            string str4;
                            string str5 ;
                            if (match.Groups["tag"].Success && match.Groups["value"].Success && (str4 = match.Groups["tag"].Value.ToUpper()) != null)
                            {
                                if (str4 == "LV_SUM")
                                    str2 = match.Groups["value"].Value;
                                else if (str4 == "LV_CAL")
                                     str5 = match.Groups["value"].Value;
                            }
                        }
                        this._source = this._source + "<TABLE style='border-collapse:collapse' border=1 cellspacing=0 cellpadding=2 bordercolor='#000000'>";
                        this._source = this._source + "<TR class=TableHeader>";
                        if (this._lvTitle != string.Empty)
                        {
                            string[] strArray = this._lvTitle.Split(new char[] { '`' });
                            if (strArray.Length > 0)
                            {
                                for (int i = 0; i < strArray.Length - 1; i++)
                                {
                                    this._source = this._source + "<TD nowrap>" + strArray[i] + "</TD>";
                                }
                            }
                        }
                        this._source = this._source + "</TR>";
                        if (this._setValue != string.Empty)
                        {
                            this._setValue = this._setValue.Replace("\r", "");
                            this._setValue = this._setValue.Replace(@"\", @"\\");
                            this._setValue = this._setValue.Replace("'", @"\'");
                            string[] strArray2 = this._setValue.Split(new char[] { '\n' });
                            if (strArray2.Length > 0)
                            {
                                string[] strArray3 = new string[0];
                                decimal[] numArray = new decimal[0];
                                if (str2.IndexOf("1") > -1)
                                {
                                    if (str2.EndsWith("`")) str2 = str2.Substring(0, str2.Length - 1);
                                    strArray3 = str2.Split(new char[] { '`' });
                                    numArray = new decimal[strArray3.Length];
                                    for (int k = 0; k < numArray.Length; k++)
                                    {
                                        numArray[k] = 0M;
                                    }
                                }
                                for (int j = 0; j < strArray2.Length - 1; j++)
                                {
                                    this._source = this._source + "<TR>";
                                    string[] strArray4 = strArray2[j].Split(new char[] { '`' });
                                    if (strArray4.Length > 0)
                                    {
                                        for (int m = 0; m < strArray4.Length - 1; m++)
                                        {
                                            if (str2.IndexOf("1") > -1 && m < strArray3.Length && strArray3[m] == "1" && Information.IsNumeric(strArray4[m])) numArray[m] += Convert.ToDecimal(strArray4[m]);
                                            this._source = this._source + "<TD nowrap>" + HttpContext.Current.Server.HtmlEncode(strArray4[m]) + "</TD>";
                                        }
                                    }
                                    this._source = this._source + "</TR>";
                                }
                                if (str2.IndexOf("1") > -1)
                                {
                                    this._source = this._source + "<TR>";
                                    for (int n = 0; n < strArray3.Length; n++)
                                    {
                                        if (strArray3[n] == "1")
                                            this._source = this._source + "<td class=TableControl align=right>合计：" + numArray[n].ToString() + "</td>";
                                        else
                                            this._source = this._source + "<td class=TableControl></td>";
                                    }
                                    this._source = this._source + "</TR>";
                                }
                            }
                        }
                        this._source = this._source + "</TABLE>";
                        return;
                    }
                    case AnyOffice.WorkFlowRegex.ControlType.MacroInput:
                        this._source = HttpContext.Current.Server.HtmlEncode(this._setValue);
                        this._source = this._source.Replace("{宏控件}", "");
                        return;

                    case AnyOffice.WorkFlowRegex.ControlType.MacroSelect:
                        string str6;
                        str = this._setValue;
                        switch (this._dataFld.ToUpper())
                        {
                            case "SYS_LIST_DEPT":
                                if (this._setValue != string.Empty)
                                {
                                    try
                                    {
                                        str6 = "SELECT [DeptName] FROM [dbo].[Department] WHERE DeptId = " + this._setValue + " ORDER BY [DeptNo] ASC";
                                        DataTable table = SqlHelper.ExecuteDataset(this.conn, CommandType.Text, str6).Tables[0];
                                        if (table.Rows.Count > 0) str = table.Rows[0]["DeptName"].ToString();
                                    }
                                    catch (Exception exception)
                                    {
                                        if (log.IsErrorEnabled) { log.Error("", exception); }
                                    }
                                }
                                goto Label_0AA5;

                            case "SYS_LIST_USER":
                                if (this._setValue != string.Empty)
                                {
                                    try
                                    {
                                        str6 = "SELECT [UserName] FROM [dbo].[Users] WHERE UserId = '" + this._setValue + "' ORDER BY [UserNo] ASC";
                                        DataTable table2 = SqlHelper.ExecuteDataset(this.conn, CommandType.Text, str6).Tables[0];
                                        if (table2.Rows.Count > 0) str = table2.Rows[0]["UserName"].ToString();
                                    }
                                    catch (Exception exception2)
                                    {
                                        if (log.IsErrorEnabled) { log.Error("", exception2); }
                                    }
                                }
                                goto Label_0AA5;

                            case "SYS_LIST_PRIV":
                                if (this._setValue != string.Empty)
                                {
                                    try
                                    {
                                        str6 = "SELECT [PrivName] FROM [dbo].[User_Priv] WHERE PrivId = " + this._setValue + " ORDER BY [PrivNo] ASC";
                                        DataTable table3 = SqlHelper.ExecuteDataset(this.conn, CommandType.Text, str6).Tables[0];
                                        if (table3.Rows.Count > 0) str = table3.Rows[0]["PrivName"].ToString();
                                    }
                                    catch (Exception exception3)
                                    {
                                        if (log.IsErrorEnabled) { log.Error("", exception3); }
                                    }
                                }
                                goto Label_0AA5;

                            case "SYS_LIST_PRCSUSER1":
                                if (this._setValue != string.Empty)
                                {
                                    try
                                    {
                                        str6 = "SELECT [UserName] FROM [dbo].[Users] WHERE UserId = '" + this._setValue + "' ORDER BY [UserNo] ASC";
                                        DataTable table4 = SqlHelper.ExecuteDataset(this.conn, CommandType.Text, str6).Tables[0];
                                        if (table4.Rows.Count > 0) str = table4.Rows[0]["UserName"].ToString();
                                    }
                                    catch (Exception exception4)
                                    {
                                        if (log.IsErrorEnabled) { log.Error("", exception4); }
                                    }
                                }
                                goto Label_0AA5;

                            case "SYS_LIST_PRCSUSER2":
                                if (this._setValue != string.Empty)
                                {
                                    try
                                    {
                                        str6 = "SELECT [UserName] FROM [dbo].[Users] WHERE UserId = '" + this._setValue + "' ORDER BY [UserNo] ASC";
                                        DataTable table5 = SqlHelper.ExecuteDataset(this.conn, CommandType.Text, str6).Tables[0];
                                        if (table5.Rows.Count > 0) str = table5.Rows[0]["UserName"].ToString();
                                    }
                                    catch (Exception exception5)
                                    {
                                        if (log.IsErrorEnabled) { log.Error("", exception5); }
                                    }
                                }
                                goto Label_0AA5;
                        }
                        goto Label_0AA5;

                    case AnyOffice.WorkFlowRegex.ControlType.Calculate:
                        this._source = HttpContext.Current.Server.HtmlEncode(this._setValue);
                        return;
                }
            }
            return;
        Label_0AA5:
            this._source = HttpContext.Current.Server.HtmlEncode(str);
        }

        private string GetUserName()
        {
            string str = "";
            str = "\n<OPTION value=''>所有</OPTION>\n";
            string str2 = "SELECT [Users].[UserId], [Users].[UserName] FROM [dbo].[Department], [dbo].[Users] WHERE CHARINDEX(',' + [Users].[UserId] + ',',',' + ISNULL(CAST([Department].[Manager] AS nvarchar(2000)),'') + ',') > 0 ORDER BY [Users].[UserNo] ASC";
            DataTable table = SqlHelper.ExecuteDataset(this.conn, CommandType.Text, str2).Tables[0];
            if (table.Rows.Count > 0)
            {
                for (int i = 0; i < table.Rows.Count; i++)
                {
                    string str3 = str;
                    str = str3 + "<OPTION value='" + table.Rows[i]["UserId"].ToString() + "'>" + table.Rows[i]["UserName"].ToString() + "</OPTION>\n";
                }
            }
            return str;
        }

        private string GetUserNameInDept1()
        {
            string str = "";
            str = "\n<OPTION value=''>所有</OPTION>\n";
            string str2 = "SELECT [Users].[UserId], [Users].[UserName] FROM [dbo].[Department], [dbo].[Users] WHERE CHARINDEX(',' + [Users].[UserId] + ',',',' + ISNULL(CAST([Department].[Leader1] AS nvarchar(2000)),'') + ',') > 0 ORDER BY [Users].[UserNo] ASC";
            DataTable table = SqlHelper.ExecuteDataset(this.conn, CommandType.Text, str2).Tables[0];
            if (table.Rows.Count > 0)
            {
                for (int i = 0; i < table.Rows.Count; i++)
                {
                    string str3 = str;
                    str = str3 + "<OPTION value='" + table.Rows[i]["UserId"].ToString() + "'>" + table.Rows[i]["UserName"].ToString() + "</OPTION>\n";
                }
            }
            return str;
        }

        private string GetUserNameInDept2()
        {
            string str = "";
            str = "\n<OPTION value=''>所有</OPTION>\n";
            string str2 = "SELECT [Users].[UserId], [Users].[UserName] FROM [dbo].[Department], [dbo].[Users] WHERE CHARINDEX(',' + [Users].[UserId] + ',',',' + ISNULL(CAST([Department].[Leader2] AS nvarchar(2000)),'') + ',') > 0 ORDER BY [Users].[UserNo] ASC";
            DataTable table = SqlHelper.ExecuteDataset(this.conn, CommandType.Text, str2).Tables[0];
            if (table.Rows.Count > 0)
            {
                for (int i = 0; i < table.Rows.Count; i++)
                {
                    string str3 = str;
                    str = str3 + "<OPTION value='" + table.Rows[i]["UserId"].ToString() + "'>" + table.Rows[i]["UserName"].ToString() + "</OPTION>\n";
                }
            }
            return str;
        }

        private string GetUsers()
        {
            string str = "";
            str = "\n<OPTION value=''>所有</OPTION>\n";
            string str2 = "SELECT [Users].[UserId],[Users].[UserName] FROM [dbo].[Department],[dbo].[Users] WHERE ([Department].[DeptId] = [Users].[DeptId]) AND ([Users].[DeptId] <> -1) ORDER BY [Department].[DeptId] ASC,[Users].[UserNo] ASC";
            DataTable table = SqlHelper.ExecuteDataset(this.conn, CommandType.Text, str2).Tables[0];
            if (table.Rows.Count > 0)
            {
                for (int i = 0; i < table.Rows.Count; i++)
                {
                    string str3 = str;
                    str = str3 + "<OPTION value='" + table.Rows[i]["UserId"].ToString() + "'>" + table.Rows[i]["UserName"].ToString() + "</OPTION>\n";
                }
            }
            return str;
        }

        public string HtmlAnalyze()
        {
            this.AnalyzeType();
            this.AnalyzeTagName();
            this.AnalyzeTagType();
            this.AnalyzeControlValue();
            this._result = this._source;
            return this._result;
        }

        public string HtmlQuery()
        {
            this.AnalyzeType();
            this.AnalyzeTagType();
            this.AnalyzeControlType();
            this._result = this._source;
            return this._result;
        }

        public string HtmlView()
        {
            this.AnalyzeType();
            this.AnalyzeTagName();
            this.AnalyzeTagType();
            this.getSourceName();
            this._result = this._source;
            return this._result;
        }

        protected void PrentDeptName(SqlConnection conn, int deptId, ref string strTemp)
        {
            string str = "SELECT [ParentDept],[DeptName] FROM [dbo].[Department] WHERE [DeptId] = " + deptId.ToString();
            DataTable table = SqlHelper.ExecuteDataset(conn, CommandType.Text, str).Tables[0];
            if (table.Rows.Count > 0)
            {
                strTemp = table.Rows[0]["DeptName"].ToString() + "/" + strTemp;
                if (Convert.ToInt32(table.Rows[0]["ParentDept"].ToString()) != 0) this.PrentDeptName(conn, Convert.ToInt32(table.Rows[0]["ParentDept"].ToString()), ref strTemp);
            }
        }

        protected void QueryChildDepartment(SqlConnection conn, ref string MacroOptionSelect, int DeptId, string strTemp)
        {
            string str = "SELECT [DeptId],[DeptName] FROM [dbo].[Department] WHERE [ParentDept]=" + DeptId.ToString() + " ORDER BY [DeptNo] ASC";
            DataTable table = SqlHelper.ExecuteDataset(conn, CommandType.Text, str).Tables[0];
            if (table.Rows.Count > 0)
            {
                strTemp = strTemp + "|　";
                for (int i = 0; i < table.Rows.Count; i++)
                {
                    string str2 = MacroOptionSelect;
                    MacroOptionSelect = str2 + "<OPTION value='" + table.Rows[i]["DeptId"].ToString() + "'>" + strTemp + "|─" + table.Rows[i]["DeptName"].ToString() + "</OPTION>\n";
                    this.QueryChildDepartment(conn, ref MacroOptionSelect, int.Parse(table.Rows[i]["DeptId"].ToString()), strTemp);
                }
            }
        }

        public bool AutoMacro
        {
            get
            {
                return this._autoMacro;
            }
            set
            {
                this._autoMacro = value;
            }
        }

        public string Class
        {
            get
            {
                return this._class;
            }
            set
            {
                this._class = value;
            }
        }

        public AnyOffice.WorkFlowRegex.ControlType ControlType
        {
            get
            {
                return this._controlType;
            }
            set
            {
                this._controlType = value;
            }
        }

        public string DataFld
        {
            get
            {
                return this._dataFld;
            }
            set
            {
                this._dataFld = value;
            }
        }

        public string DataSrc
        {
            get
            {
                return this._dataSrc;
            }
            set
            {
                this._dataSrc = value;
            }
        }

        public string FormName
        {
            get
            {
                return this._formName;
            }
            set
            {
                this._formName = value;
            }
        }

        public bool Hidden
        {
            get
            {
                return this._hidden;
            }
            set
            {
                this._hidden = value;
            }
        }

        public string LvSize
        {
            get
            {
                return this._lvSize;
            }
            set
            {
                this._lvSize = value;
            }
        }

        public string LvTitle
        {
            get
            {
                return this._lvTitle;
            }
            set
            {
                this._lvTitle = value;
            }
        }

        public string Name
        {
            get
            {
                return this._name;
            }
            set
            {
                this._name = value;
            }
        }

        public Hashtable PrcsUser1
        {
            get
            {
                return this._prcsUser1;
            }
            set
            {
                this._prcsUser1 = value;
            }
        }

        public Hashtable PrcsUser2
        {
            get
            {
                return this._prcsUser2;
            }
            set
            {
                this._prcsUser2 = value;
            }
        }

        public bool ReadOnly
        {
            get
            {
                return this._readOnly;
            }
            set
            {
                this._readOnly = value;
            }
        }

        public string Result
        {
            get
            {
                return this._result;
            }
            set
            {
                this._result = value;
            }
        }

        public DateTime RunDateTime
        {
            get
            {
                return this._runDateTime;
            }
            set
            {
                this._runDateTime = value;
            }
        }

        public int RunId
        {
            get
            {
                return this._runId;
            }
            set
            {
                this._runId = value;
            }
        }

        public string RunName
        {
            get
            {
                return this._runName;
            }
            set
            {
                this._runName = value;
            }
        }

        public int Sequence
        {
            get
            {
                return this._sequence;
            }
            set
            {
                this._sequence = value;
            }
        }

        public string SetValue
        {
            get
            {
                return this._setValue;
            }
            set
            {
                this._setValue = value;
            }
        }

        public string Source
        {
            get
            {
                return this._source;
            }
            set
            {
                this._source = value;
            }
        }

        public string Tag
        {
            get
            {
                return this._tag;
            }
            set
            {
                this._tag = value;
            }
        }

        public string Title
        {
            get
            {
                return this._title;
            }
            set
            {
                this._title = value;
            }
        }

        public string Type
        {
            get
            {
                return this._type;
            }
            set
            {
                this._type = value;
            }
        }

        public string Value
        {
            get
            {
                return this._value;
            }
            set
            {
                this._value = value;
            }
        }
    }
}

